"""集合类型配置

包含set类型的C++映射和方法配置
"""

# 集合类型配置
CONFIG = {
    "set[T]": {
        "cpp_type": "mcpy::variant_set",  # 统一使用弱类型，和 dict 一样
        "includes": [
            "mcpy/builtins/set.h",
        ],
        "default_value": "mcpy::variant_set()",
        "pass_by": "const_ref",  # 容器按常量引用传递
        "generic_params": ["T"],  # 泛型参数
        "iterator_element_type": "T",  # 迭代器元素类型
        "satisfies_protocols": ["Iterable", "Sized", "Container"],  # 满足的 Protocol
        "methods": {
            "add": {
                "signatures": ["add(self, item: T) -> None"],
                "templates": ["{self}.insert({item})"],
                "includes": [],
                "priority": 1,
                "mutating": True,
            },
            "remove": {
                "signatures": ["remove(self, item: T) -> None"],
                "templates": ["mcpy::set_remove({self}, {item})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "discard": {
                "signatures": ["discard(self, item: T) -> None"],
                "templates": ["{self}.erase({item})"],
                "includes": [],
                "priority": 1,
                "mutating": True,
            },
            "clear": {
                "signatures": ["clear(self) -> None"],
                "templates": ["{self}.clear()"],
                "includes": [],
                "priority": 1,
                "mutating": True,
            },
            "union": {
                "signatures": ["union(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_union({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "intersection": {
                "signatures": ["intersection(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_intersection({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "difference": {
                "signatures": ["difference(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_difference({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "symmetric_difference": {
                "signatures": ["symmetric_difference(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_symmetric_difference({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "update": {
                "signatures": ["update(self, other: set[T]) -> None"],
                "templates": ["mcpy::set_update({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "intersection_update": {
                "signatures": ["intersection_update(self, other: set[T]) -> None"],
                "templates": ["mcpy::set_intersection_update({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "difference_update": {
                "signatures": ["difference_update(self, other: set[T]) -> None"],
                "templates": ["mcpy::set_difference_update({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "symmetric_difference_update": {
                "signatures": [
                    "symmetric_difference_update(self, other: set[T]) -> None"
                ],
                "templates": ["mcpy::set_symmetric_difference_update({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "issubset": {
                "signatures": ["issubset(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_issubset({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "issuperset": {
                "signatures": ["issuperset(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_issuperset({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "isdisjoint": {
                "signatures": ["isdisjoint(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_isdisjoint({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "copy": {
                "signatures": ["copy(self) -> set[T]"],
                "templates": ["{self}.copy()"],
                "includes": [],
                "priority": 1,
            },
            "__len__": {
                "signatures": ["__len__(self) -> int"],
                "templates": ["{self}.size()"],
                "includes": [],
                "priority": 1,
            },
            "__iter__": {
                "signatures": ["__iter__(self) -> Iterator[T]"],
                "templates": ["mcpy::iter_wrapper({self})"],
                "includes": ["mcpy/builtins/global_functions.h"],
                "priority": 1,
            },
            "__next__": {
                "signatures": ["__next__(self) -> T"],
                "templates": ["{self}.__next__()"],
                "includes": ["mcpy/builtins/global_functions.h"],
                "priority": 1,
            },
            "__contains__": {
                "signatures": ["__contains__(self, item: T) -> bool"],
                "templates": ["mcpy::set_contains({self}, {item})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__bool__": {
                "signatures": ["__bool__(self) -> bool"],
                "templates": ["!{self}.empty()"],
                "includes": [],
                "priority": 1,
            },
            "pop": {
                "signatures": ["pop(self) -> T"],
                "templates": [
                    "mcpy::set_pop<{T}>({self})"
                ],  # 关键：模板参数，和 dict_pop 一样
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            # 集合运算符
            "__or__": {
                "signatures": ["__or__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_union({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__and__": {
                "signatures": ["__and__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_intersection({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__sub__": {
                "signatures": ["__sub__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_difference({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__xor__": {
                "signatures": ["__xor__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_symmetric_difference({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            # 原地运算符
            "__ior__": {
                "signatures": ["__ior__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_ior({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "__iand__": {
                "signatures": ["__iand__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_iand({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "__isub__": {
                "signatures": ["__isub__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_isub({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            "__ixor__": {
                "signatures": ["__ixor__(self, other: set[T]) -> set[T]"],
                "templates": ["mcpy::set_ixor({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
                "mutating": True,
            },
            # 比较运算符
            "__le__": {
                "signatures": ["__le__(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_issubset({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__ge__": {
                "signatures": ["__ge__(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_issuperset({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__lt__": {
                "signatures": ["__lt__(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_is_proper_subset({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__gt__": {
                "signatures": ["__gt__(self, other: set[T]) -> bool"],
                "templates": ["mcpy::set_is_proper_superset({self}, {other})"],
                "includes": ["mcpy/builtins/set.h"],
                "priority": 1,
            },
            "__eq__": {
                "signatures": ["__eq__(self, other: set[T]) -> bool"],
                "templates": ["{self} == {other}"],
                "includes": [],
                "priority": 1,
            },
            "__ne__": {
                "signatures": ["__ne__(self, other: set[T]) -> bool"],
                "templates": ["{self} != {other}"],
                "includes": [],
                "priority": 1,
            },
        },
        # 构造函数配置
        "constructors": {
            "signatures": [
                "set() -> set[T]",
                "set(iterable: list[T]) -> set[T]",
                "set(iterable: tuple[T]) -> set[T]",
                "set(iterable: set[T]) -> set[T]",
                "set(value: Any) -> set[T]",  # 从 Any 转换
            ],
            "templates": [
                "mcpy::variant_set{}",  # 统一使用别名
                "mcpy::set_construct<{T}>({iterable})",  # 模板参数
                "mcpy::set_construct<{T}>({iterable})",
                "mcpy::set_construct<{T}>({iterable})",
                "mcpy::set_from_any<{T}>({value})",  # 模板参数
            ],
            "includes": ["mcpy/builtins/set.h"],
            "priority": 1,
        },
    },
    # 无类型注解的集合配置（弱类型）
    "set": {
        "cpp_type": "mcpy::variant_set",  # 统一使用别名，和 dict 一样
        "default_type": "mc::variant",  # 默认类型参数
        "generic_params": ["T"],  # 模板参数名列表
        "default_constructor_syntax": "parens",  # 使用 () 构造
        "includes": [
            "mcpy/builtins/set.h",
            "<mc/variant.h>",
        ],
        "default_value": "mcpy::variant_set{}",
        "is_type": True,
        "module": "builtins",
        "inherit_from": "set[T]",
        "type_substitution": {"T": "Any"},  # 关键配置，和 dict 一样
        "satisfies_protocols": ["Iterable", "Sized", "Container"],  # 满足的 Protocol
    },
    # Python 3.9+ 兼容性：大写类型映射
    "Set": {
        "is_type": True,
        "type_alias": "set",
        "module": "typing",
    },
}
